<?php
//This is the inbox-view for the message-inbox for the 'logged_in_user'
//Still needs threading for responses/etc

echo heading("Your Inbox",3);
echo "inbox" . nbs(2) . "|" . nbs(2);
echo anchor("messages/sent", "sent") . nbs(2) . "|" . nbs(2);
echo anchor("messages/archive", "archives");

//Initializing the table-array
$TABLE = array();

//time format!
$format = "%d/%m/%Y %h:%i %a";

//If any messagess, add them to the table-array.
echo br(2);
if (count($messages)){
	foreach ($messages as $key => $msg){
		$stamp = mysql_to_unix($msg->created);
		$TABLE[] = $usernames[$msg->from_id];
		$TABLE[] =	$usernames[$msg->to_id];
		$TABLE[] = anchor("messages/view_message/".$msg->id, $msg->subject);
		$TABLE[] =  mdate($format,$stamp);
	}

        //Structure the table array of messages, so it looks pretty.
	$tmpl = array (
		'table_open'  => "<table class='messages'><tr valign='bottom'><th>From</th><th>To</th><th>Subject</th><th>Date/Time</th></tr>",
		'row_start'   => "<tr valign='top'>",
	);
	$this->table->set_template($tmpl);
	$this->table->set_empty("&nbsp;");
	$pretty = $this->table->make_columns($TABLE,4);
	
	echo $this->table->generate($pretty);


}
else
{
    echo "No messages in inbox!";
}
?>